using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using VitServer;

namespace protoNet
{
    public class MsgSender
    {
        
        // 最终向服务器Send的函数
        private static void SendMessage(GAME_PROTOCOL_MSG_ID msgId, object data, string urlQuery ,string host = null)
        {
            Serialize sl = new Serialize(msgId, data);
            _G.Print("Sending message: ID = " + msgId);
            
            NetDealer.Instance.Send(_G.CreateUrl(urlQuery, host), sl.SerializedBuffer);
            _G.Print("Send message success, ID = " + msgId);
        }

        // 发送请求游客登陆
        public static void SendID_C2S_GUEST()
        {
            MsgGuestReq req = new MsgGuestReq()
            {              
                openId = "testID",
                serverIndex = 1
            };
            req.sign = _G.GetSignByOpenId(req.openId);
            SendMessage(GAME_PROTOCOL_MSG_ID.ID_C2S_GUEST, req, "guestLogin");
        }

        // 发送请求登陆消息
        public static void SendID_C2S_ACCOUNT(string Account, string passWord)
        {
            MsgAccountReq req = new MsgAccountReq()
            {
                account = Account,  // 账号    
                password = passWord,    // 密码
                serverIndex = 1
            };
            req.sign = _G.GetSignByOpenId(req.account);
            SendMessage(GAME_PROTOCOL_MSG_ID.ID_C2S_ACCOUNT, req, "login");
        }
        // 发送请求注册消息
        public static void SendID_C2S_REGISTER(string Account, string passWord)
        {
            MsgRegisterReq req = new MsgRegisterReq()
            {
                account = Account,  // 账号    
                password = passWord,    // 密码
                serverIndex = 1
            };
            req.sign = _G.GetSignByOpenId(req.account);
            SendMessage(GAME_PROTOCOL_MSG_ID.ID_C2S_REGISTER, req, "register");
        }
        // 发送请求NOTICE消息
        public static void SendID_C2S_NOTICE()
        {
            MsgNoticeReq req = new MsgNoticeReq()
            {
                serverIndex = 1
            };
            SendMessage(GAME_PROTOCOL_MSG_ID.ID_C2S_NOTICE, req, "notice");
        }
        //发送登录大厅请求
        public static void SendID_C2S_LOGIN_LOBBY(string _token , string _ip , string host)
        {
            MsgLoginLobbyReq req = new MsgLoginLobbyReq()
            {
                token = _token,
                ip = _ip
            };
            SendMessage(GAME_PROTOCOL_MSG_ID.ID_C2S_LOGIN_LOBBY, req, "LoginLobby" , host);
        }
    }
}
